package cn.tedu.boot05.controller;

import cn.tedu.boot05.entity.User;
import cn.tedu.boot05.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    UserMapper mapper;
    @RequestMapping("/reg")
    public String reg(User user){
        User u= mapper.selectByUsername(user.getUsername());
        if(u!=null){
            return "用户名已存在!";
        }
        mapper.insert(user);
        return "注册成功！<a href='/'>返回首页</a>";
    }
    @RequestMapping("/login")
    public String login(User user){
        User u= mapper.selectByUsername(user.getUsername());
        if(u==null){
            return "用户名不存在!";
        }
        if(user.getPassword().equals(u.getPassword())){
            return "登录成功！<a href='/'>返回首页</a>";
        }
        return "密码错误！<a href='/'>返回首页</a>";
    }
}
